// pages/reading/reading.js
var app = getApp()
const $api = require('../../utils/api.js').API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    navbarData: {
      havebg: 1, //1表示显示    0表示不显示
      out: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '阅读守则', //导航栏 中间的标题
      bg: '#fff', //导航背景
    },
    height: app.globalData.height,
    step: 0, //步骤是否隐藏 0隐藏 1显示
    state: 1, //1==阅读守则  2==填写信息  3==购买礼包  4==等待审核
    informationState: 1, //1==个人信息 2==店铺信息 3==营业执照信息
    adjust: true, //详细地址的键盘弹起时，是否自动上推页面,不要动，一直这样
    applyShop: { //店铺申请信息
      real_name: '', //用户姓名
      sex: 0, //性别 0未知 1男 2女
      phone: '', //手机号
      join_time: '', //加盟时间
      id_card: '', //身份证号码
      shg_province_id: '', //臻元气省id
      shg_city_id: '', //臻元气市id
      shg_area_id: '', //臻元气区id
      shg_address: '', //臻元气详细地址
      house_owner_type: 0, //房屋所有权 1 自有 2 租赁 0 未选择
      lease_term: '', //租赁期限
      shg_area: '', //臻元气面积
      is_jianying: 0, //是否兼营 1是2否 0 未选择
      has_license: 1, //是否有营业执照1有2没有
      license_img: '', //营业执照照片
      house_img: '', //房本或租赁协议
      door_img: '', //门头照片
      house_area: '', //房屋总面积
      nag_distance: '', //地点离最近暖艾馆距离
      social_credit_code: '', //统一社会信用代码
      register_date: '', //注册日期
      company_name: '', //商户名称
      company_provice: '', //商户所在省id
      company_city: '', //商户所在市id
      company_area: '', //商户所在区id
      company_address: '', //商户详细地址
      shop_level_type: false,
      ptType: '',//1.普通购物商品

    },
    regionIndex: [0, 0, 0], //地址省市区默认下标
    addressSHQ: ['省', '市', '区'],
    totalPrice: '0.00', //合计
    wait_pay: 0, //待支付修改 1是0不是
    shop_id: '',
    companySH: ['省', '市', '区'],
    goodsListProduct: false, //商品详情的展开折叠
    giftId: '', //礼包id
    giftList: [], //礼包详情
    dzy: 0,
    imglist: [],
    payTime: 0,
    giftInfoList: [],
    scType: '',//首次进入1
    state: 3,
    stateTypeBj: 'https://jiujinimg.tjnanguyi.com/zhenyuanqi/yuedubeijing.png',
    stateTypeTitle: 'https://jiujinimg.tjnanguyi.com/zhenyuanqi/yueduzhunze.png',
    stateTypeBut: '申请店铺守则',
    stateTypebuz: '申请店铺守则',
    zbgoodsType: '',//直播商品1
  },
  onLoad: function (options) {

    var _this = this;
    options.status = options.status ? options.status : ''
    options.UpLevelType = options.UpLevelType ? options.UpLevelType : ''
    options.pzimg = options.pzimg ? options.pzimg : ''
    options.scType = options.scType ? options.scType : ''
    options.is_sj = options.is_sj ? options.is_sj : 0
    options.ptType = options.ptType ? options.ptType : ''
    options.zbgoodsType = options.zbgoodsType ? options.zbgoodsType : ''
    console.log(options,)

    wx.setStorageSync('statusReading', options.status)
    _this.setData({
      state: options.state,
      addresstype: options.type,
      status: options.status,
      twoType: options.twoType,
      UpLevelType: options.UpLevelType,
      shop_id: options.shop_id,
      pzimg: options.pzimg,
      scType: options.scType,
      is_sj: options.is_sj,
      ptType: options.ptType,
      zbgoodsType: options.zbgoodsType,
      is_register:options.is_register,
    })
    if (options.dzy == 1) {
      _this.setData({
        dzy: options.dzy
      })
    }
    if (options.step) {
      _this.setData({
        step: options.step,
      })
    }

    //1==阅读守则  2==填写信息  3==购买礼包  4==等待审核
    if (options.state == 1) {
      _this.setData({
        loadModal: true
      })
      //获取店铺规则
      $api.getShopRules({
        login_token: wx.getStorageSync('login_token')
      }).then((res) => {
        _this.setData({
          loadModal: false,
          shopRules: res.data.data
        })
      }).catch((err) => {
        _this.setData({
          loadModal: false
        })
      })
      //获取加盟时间
      var timestamp = Date.parse(new Date());
      var date = new Date(timestamp);
      //获取年份  
      var Y = date.getFullYear();
      //获取月份  
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
      //获取当日日期 
      var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
      _this.setData({
        ['applyShop.join_time']: Y + '-' + M + '-' + D
      })
      if (options.UpLevelType == 1) {
        $api.getApplyShopDetail({
          login_token: wx.getStorageSync('login_token'),
          has_order: 1,
          shop_id: options.shop_id,
          is_detail: 0,
        }).then((res) => {
          // res.data.data.lb_lists.forEach((item) => {
          //   if (item.id == res.data.data.order_detail_info[0].id) {
          //     item.number = res.data.data.order_detail_info[0].num
          //   }
          // })
          console.log(res.data.data.shop_info, 11)
          let addressSHQ = [
            res.data.data.shop_info.shg_province_name,
            res.data.data.shop_info.shg_city_name,
            res.data.data.shop_info.shg_area_name,

          ]
          wx.setStorageSync('addressSHQ', addressSHQ)
          _this.setData({
            addressSHQ: addressSHQ,
            ['applyShop.real_name']: res.data.data.shop_info.real_name,//
            ['applyShop.sex']: res.data.data.shop_info.sex,
            ['applyShop.phone']: res.data.data.shop_info.phone,//
            ['applyShop.join_time']: res.data.data.shop_info.join_time,
            ['applyShop.id_card']: res.data.data.shop_info.id_card,//
            ['applyShop.shg_province_id']: res.data.data.shop_info.shg_province_id,
            // ['addressSHQ[0]']: res.data.data.shop_info.shg_province_name,
            ['applyShop.shg_city_id']: res.data.data.shop_info.shg_city_id,
            // ['addressSHQ[1]']: res.data.data.shop_info.shg_city_name,
            ['applyShop.shg_area_id']: res.data.data.shop_info.shg_area_id,
            // ['addressSHQ[2]']: res.data.data.shop_info.shg_area_name,

            ['applyShop.shg_address']: res.data.data.shop_info.shg_address,
            ['applyShop.house_owner_type']: res.data.data.shop_info.house_owner_type,
            ['applyShop.lease_term']: res.data.data.shop_info.lease_term,
            ['applyShop.shg_area']: res.data.data.shop_info.shg_area,
            ['applyShop.is_jianying']: res.data.data.shop_info.is_jianying,
            ['applyShop.has_license']: res.data.data.shop_info.has_license,
            ['applyShop.license_img']: res.data.data.shop_info.license_img,
            ['applyShop.house_img']: res.data.data.shop_info.house_img,
            ['applyShop.door_img']: res.data.data.shop_info.door_img,
            ['applyShop.house_area']: res.data.data.shop_info.house_area,
            ['applyShop.nag_distance']: res.data.data.shop_info.nag_distance,
            ['applyShop.social_credit_code']: res.data.data.shop_info.social_credit_code,
            ['applyShop.register_date']: res.data.data.shop_info.register_date,
            ['applyShop.company_name']: res.data.data.shop_info.company_name,
            ['companySH[0]']: res.data.data.shop_info.company_province_name,
            ['applyShop.company_provice']: res.data.data.shop_info.company_provice,
            ['companySH[1]']: res.data.data.shop_info.company_city_name,
            ['applyShop.company_city']: res.data.data.shop_info.company_city,
            ['companySH[2]']: res.data.data.shop_info.company_area_name,
            ['applyShop.company_area']: res.data.data.shop_info.company_area,
            ['applyShop.company_address']: res.data.data.shop_info.company_address,
            ['applyShop.shop_level']: '',
            ['applyShop.shop_level_type']: false,
            wait_pay: 1,
            goodsList: res.data.data.lb_lists,
            totalPrice: res.data.data.order_info.price,
            CsUpshop_level: res.data.data.shop_info.shop_level
          })

          wx.setStorageSync('CsUpshop_level', res.data.data.shop_info.shop_level)
          console.log(res.data.data, 555)
          _this.setData({
            userAddressData: res.data.data.address_info,
            addressid: res.data.data.address_info.id,
            ['userAddressData.addressSHQ']: [res.data.data.address_info.province_name, res.data.data.address_info.city_name, res.data.data.address_info.area_name]
          })
          console.log(_this.data.userAddressData, 666)
          wx.setStorageSync('address', _this.data.userAddressData)
          wx.setStorageSync('addressid', _this.data.addressid)


          $api.getGoodsProducts({
            login_token: wx.getStorageSync('login_token'),
            good_id: res.data.data.order_detail_info[0].id
          }).then((res) => {
            _this.setData({
              giftList: res.data.data,
              loadModal: false
            })
          }).catch((err) => {
            _this.setData({
              loadModal: false
            })
          })


        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      }
    } else if (options.state == 2 && options.wszl != 1) {
      //修改是进入
      _this.setData({
        ['navbarData.title']: '填写信息',
        shop_id: options.shop_id,
        loadModal: true,
        dzy: options.dzy
      })

      $api.getApplyShopDetail({
        login_token: wx.getStorageSync('login_token'),
        has_order: 1,
        shop_id: options.shop_id,
        is_detail: 0,
      }).then((res) => {

        res.data.data.order_detail_info.forEach((citem) => {
          citem.number = citem.num
          citem.check = true
        })
        let giftInfoList = res.data.data.order_detail_info
        console.log(res.data.data.shop_info, 22)
        let imglist = res.data.data.shop_info.fukuan_imgs ? JSON.parse(res.data.data.shop_info.fukuan_imgs) : []
        _this.setData({
          ['applyShop.real_name']: res.data.data.shop_info.real_name,//
          ['applyShop.sex']: res.data.data.shop_info.sex,
          ['applyShop.phone']: res.data.data.shop_info.phone,//
          ['applyShop.join_time']: res.data.data.shop_info.join_time,
          ['applyShop.id_card']: res.data.data.shop_info.id_card,//
          ['applyShop.shg_province_id']: res.data.data.shop_info.shg_province_id,
          ['addressSHQ[0]']: res.data.data.shop_info.shg_province_name,
          ['applyShop.shg_city_id']: res.data.data.shop_info.shg_city_id,
          ['addressSHQ[1]']: res.data.data.shop_info.shg_city_name,
          ['applyShop.shg_area_id']: res.data.data.shop_info.shg_area_id,
          ['addressSHQ[2]']: res.data.data.shop_info.shg_area_name,
          ['applyShop.shg_address']: res.data.data.shop_info.shg_address,
          ['applyShop.house_owner_type']: res.data.data.shop_info.house_owner_type,
          ['applyShop.lease_term']: res.data.data.shop_info.lease_term,
          ['applyShop.shg_area']: res.data.data.shop_info.shg_area,
          ['applyShop.is_jianying']: res.data.data.shop_info.is_jianying,
          ['applyShop.has_license']: res.data.data.shop_info.has_license,
          ['applyShop.license_img']: res.data.data.shop_info.license_img,
          ['applyShop.house_img']: res.data.data.shop_info.house_img,
          ['applyShop.door_img']: res.data.data.shop_info.door_img,
          ['applyShop.house_area']: res.data.data.shop_info.house_area,
          ['applyShop.nag_distance']: res.data.data.shop_info.nag_distance,
          ['applyShop.social_credit_code']: res.data.data.shop_info.social_credit_code,
          ['applyShop.register_date']: res.data.data.shop_info.register_date,
          ['applyShop.company_name']: res.data.data.shop_info.company_name,
          ['companySH[0]']: res.data.data.shop_info.company_province_name,
          ['applyShop.company_provice']: res.data.data.shop_info.company_provice,
          ['companySH[1]']: res.data.data.shop_info.company_city_name,
          ['applyShop.company_city']: res.data.data.shop_info.company_city,
          ['companySH[2]']: res.data.data.shop_info.company_area_name,
          ['applyShop.company_area']: res.data.data.shop_info.company_area,
          ['applyShop.company_address']: res.data.data.shop_info.company_address,
          ['applyShop.shop_level']: res.data.data.shop_info.shop_level,
          ['applyShop.shop_level_type']: res.data.data.shop_info.shop_level ? true : false,
          wait_pay: 1,
          goodsList: res.data.data.lb_lists,
          totalPrice: res.data.data.order_info.price,
          giftId: res.data.data.order_detail_info[0].id,
          giftnumber: res.data.data.order_detail_info[0].num,
          giftInfoList,
          imglist
        })

        _this.setData({
          userAddressData: res.data.data.address_info,
          addressid: res.data.data.address_info.id,
          ['userAddressData.addressSHQ']: [res.data.data.address_info.province_name, res.data.data.address_info.city_name, res.data.data.address_info.area_name]
        })
        console.log(_this.data.userAddressData, 888)
        wx.setStorageSync('address', _this.data.userAddressData)
        wx.setStorageSync('addressid', _this.data.addressid)
        wx.setStorageSync('giftInfoList', giftInfoList)

        $api.getGoodsProducts({
          login_token: wx.getStorageSync('login_token'),
          good_id: res.data.data.order_detail_info[0].id
        }).then((res) => {
          _this.setData({
            giftList: res.data.data,
            loadModal: false
          })
        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })


      }).catch((err) => {
        _this.setData({
          loadModal: false
        })
      })
    } else if (options.state == 3) {
      var goods = options.goods;
      goods = JSON.parse(goods)
      console.log(goods)
      if (options.twoType == 1 || options.ptType == 1) {
        let buy_goods = []
        goods.forEach((item) => {
          buy_goods.push({
            good_id: item.id,
            num: item.num,
          })
        })
        $api.getferightfee({
          login_token: wx.getStorageSync('login_token'),
          buy_goods: JSON.stringify(buy_goods),
          type: options.is_register,
          is_live: options.zbgoodsType ? 1 : 0
        }).then((res) => {
          let fee = res.data.data
          var totalPrice = 0;
          for (var i = 0; i < goods.length; i++) {
            totalPrice = totalPrice + parseFloat(goods[i].price * goods[i].num);
          }
          totalPrice = Number(totalPrice.toFixed(2)) + Number(fee); //合计价格
          totalPrice = totalPrice.toFixed(2)
          _this.setData({
            fee,
            ['navbarData.title']: '确认订单',
            pay: 1, //支付按钮显示
            goodsList: goods,
            totalPrice: totalPrice,

          })
        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
        var totalPrice = 0;
        for (var i = 0; i < goods.length; i++) {
          totalPrice = totalPrice + parseFloat(goods[i].price * goods[i].num);
        }
        totalPrice = totalPrice.toFixed(2); //合计价格
        _this.setData({
          ['navbarData.title']: '确认订单',
          pay: 1, //支付按钮显示
          goodsList: goods,
          totalPrice: totalPrice,
        })
      } else {
        var totalPrice = 0;
        for (var i = 0; i < goods.length; i++) {
          totalPrice = totalPrice + parseFloat(goods[i].price * goods[i].num);
        }
        totalPrice = totalPrice.toFixed(2); //合计价格
        _this.setData({
          ['navbarData.title']: '确认订单',
          pay: 1, //支付按钮显示
          goodsList: goods,
          totalPrice: totalPrice,
        })
      }
    } else if (options.wszl == 1) {
      _this.setData({
        ['navbarData.title']: '填写信息',
        stateTypeTitle: 'https://jiujinimg.tjnanguyi.com/zhenyuanqi/tianxiexinxi.png',
        stateTypeBut: '填写个人信息',
        stateTypebuz: '个人信息',
        wszl: options.wszl,
        state: options.state,
        informationState: options.informationState,
        loadModal: true,
        step: 1
      })
      $api.getShopStatusNew({
        login_token: wx.getStorageSync('login_token')
      }).then((res) => {
        _this.setData({
          shop_id: res.data.data.shop_id
        })
        $api.getApplyShopDetail({
          login_token: wx.getStorageSync('login_token'),
          has_order: 1,
          shop_id: res.data.data.shop_id,
          is_detail: 0,
        }).then((res) => {
          res.data.data.order_detail_info.forEach((citem) => {
            citem.number = citem.num
            citem.check = true
          })
          let giftInfoList = res.data.data.order_detail_info
          console.log(res.data.data.shop_info, 22)
          let imglist = res.data.data.shop_info.fukuan_imgs ? JSON.parse(res.data.data.shop_info.fukuan_imgs) : []
          _this.setData({
            ['applyShop.real_name']: res.data.data.shop_info.real_name,//
            ['applyShop.sex']: res.data.data.shop_info.sex,
            ['applyShop.phone']: res.data.data.shop_info.phone,//
            ['applyShop.join_time']: res.data.data.shop_info.join_time,
            ['applyShop.id_card']: res.data.data.shop_info.id_card,//
            ['applyShop.shg_province_id']: res.data.data.shop_info.shg_province_id,
            ['addressSHQ[0]']: res.data.data.shop_info.shg_province_name,
            ['applyShop.shg_city_id']: res.data.data.shop_info.shg_city_id,
            ['addressSHQ[1]']: res.data.data.shop_info.shg_city_name,
            ['applyShop.shg_area_id']: res.data.data.shop_info.shg_area_id,
            ['addressSHQ[2]']: res.data.data.shop_info.shg_area_name,
            ['applyShop.shg_address']: res.data.data.shop_info.shg_address,
            ['applyShop.house_owner_type']: res.data.data.shop_info.house_owner_type,
            ['applyShop.lease_term']: res.data.data.shop_info.lease_term,
            ['applyShop.shg_area']: res.data.data.shop_info.shg_area,
            ['applyShop.is_jianying']: res.data.data.shop_info.is_jianying,
            ['applyShop.has_license']: res.data.data.shop_info.has_license,
            ['applyShop.license_img']: res.data.data.shop_info.license_img,
            ['applyShop.house_img']: res.data.data.shop_info.house_img,
            ['applyShop.door_img']: res.data.data.shop_info.door_img,
            ['applyShop.house_area']: res.data.data.shop_info.house_area,
            ['applyShop.nag_distance']: res.data.data.shop_info.nag_distance,
            ['applyShop.social_credit_code']: res.data.data.shop_info.social_credit_code,
            ['applyShop.register_date']: res.data.data.shop_info.register_date,
            ['applyShop.company_name']: res.data.data.shop_info.company_name,
            ['companySH[0]']: res.data.data.shop_info.company_province_name,
            ['applyShop.company_provice']: res.data.data.shop_info.company_provice,
            ['companySH[1]']: res.data.data.shop_info.company_city_name,
            ['applyShop.company_city']: res.data.data.shop_info.company_city,
            ['companySH[2]']: res.data.data.shop_info.company_area_name,
            ['applyShop.company_area']: res.data.data.shop_info.company_area,
            ['applyShop.company_address']: res.data.data.shop_info.company_address,
            ['applyShop.shop_level']: res.data.data.shop_info.shop_level,
            ['applyShop.shop_level_type']: res.data.data.shop_info.shop_level ? true : false,
            wait_pay: 1,
            goodsList: res.data.data.lb_lists,
            totalPrice: res.data.data.order_info.price,
            giftId: res.data.data.order_detail_info[0].id,
            giftnumber: res.data.data.order_detail_info[0].num,
            giftInfoList,
            imglist
          })

          _this.setData({
            userAddressData: res.data.data.address_info,
            addressid: res.data.data.address_info.id,
            ['userAddressData.addressSHQ']: [res.data.data.address_info.province_name, res.data.data.address_info.city_name, res.data.data.address_info.area_name]
          })

        })

      })
    }


  },
  onShow() {
    var _this = this;
    if (_this.data.is_choose_img) {
      _this.setData({ is_choose_img: false })
      return
    }
    //获取地址
    $api.getArea({
      login_token: wx.getStorageSync('login_token'),
    }).then((res) => {
      _this.setData({
        addressJson: res.data.data,
      })
    }).catch((err) => {
      wx.showToast({
        title: '地址获取失败',
        icon: 'none',
        duration: 2000
      })
    })
    var addressid = wx.getStorageSync('addressid') ? wx.getStorageSync('addressid') : ''
    console.log(addressid, 9999)
    $api.getUserAddressList({
      login_token: wx.getStorageSync('login_token'),
      is_default: addressid ? 0 : 1,
      address_id: addressid ? addressid : ''
    }).then((res) => {
      _this.setData({
        userAddressData: res.data.data[0],
        loadModal: false,
        addressid: res.data.data[0].id
      })

    }).catch((err) => {
      _this.setData({
        loadModal: false
      })
    })

    //添加地址后进入
    if (_this.data.addresstype == 1) {
      _this.setData({
        applyShop: wx.getStorageSync('applyShop'),
        wait_pay: wx.getStorageSync('wait_pay'),
        default_lb_num: wx.getStorageSync('default_lb_num'),
        lb_num_setting: wx.getStorageSync('lb_num_setting'),
        giftId: wx.getStorageSync('giftId'),
        giftnumber: wx.getStorageSync('giftnumber'),
        state: 3,
        step: _this.data.step,
        shop_id: wx.getStorageSync('shop_id'),
      })
      _this.setData({
        loadModal: true
      })
      console.log(111, 1)
      let UpLevelType = wx.getStorageSync('UpLevelType')
      let applyShop = wx.getStorageSync('applyShop')
      //获取首次配货产品
      $api.getRegisterGoods({
        login_token: wx.getStorageSync('login_token'),
        type: UpLevelType == 1 ? 2 : 1,
        shop_level: UpLevelType != 1 ? applyShop.shop_level : ''
      }).then((res) => {
        var totalPrice = 0;
        let applyShop = wx.getStorageSync('applyShop')
        let UpLevelType = wx.getStorageSync('UpLevelType')
        let faultnum = wx.getStorageSync('faultnum')
        let lb_num_setting = wx.getStorageSync('lb_num_setting')

        let imglist = wx.getStorageSync('imglist') ? wx.getStorageSync('imglist') : []
        let giftId = wx.getStorageSync('giftId')
        let giftnumber = wx.getStorageSync('giftnumber')
        let pzimg = wx.getStorageSync('pzimg')
        let scType = wx.getStorageSync('scType')
        let giftInfoList = wx.getStorageSync('giftInfoList') ? wx.getStorageSync('giftInfoList') : []
        _this.setData({ pzimg, imglist, scType })
        console.log(applyShop, 668)
        let default_lb_num = _this.data.default_lb_num
        if (UpLevelType == 1) {
          _this.setData({ addressSHQ: wx.getStorageSync('addressSHQ'), })
        }
        let start = 1
        if (UpLevelType == 1) {
          start = 1
          res.data.data.forEach((item) => {
            item.number = start
            giftInfoList.forEach((citem) => {
              if (item.id == citem.id) {
                item.number = citem.number
                item.check = true
              }
            })
          })
        } else if (default_lb_num) {
          start = 1
          // applyShop.shop_level == 1 ? default_lb_num[1].min : applyShop.shop_level == 2 ? default_lb_num[2].min : applyShop.shop_level == 3 ? default_lb_num[3].min : 1
          console.log(start, 11)
          res.data.data.forEach((item) => {
            item.number = start
          })
        }
        // for (var i = 0; i < res.data.data.length; i++) {
        //   if (_this.data.giftId == res.data.data[i].id) {
        //     totalPrice = totalPrice + parseFloat(res.data.data[i].price)
        //     res.data.data[i].number = _this.data.giftnumber
        //   }
        // }
        res.data.data.forEach((item) => {
          item.number = start
          giftInfoList.forEach((citem) => {
            if (item.id == citem.id) {
              totalPrice = totalPrice + parseFloat(item.price)
              item.number = citem.number
              item.check = true
            }
          })
        })
        totalPrice = totalPrice.toFixed(2)
        _this.setData({
          goodsList: res.data.data,
          loadModal: false,
          // state: 3,
          // ['navbarData.title']: '购买礼包',
          totalPrice: totalPrice,
          UpLevelType: UpLevelType,
          faultnum: faultnum,
          lb_num_setting: lb_num_setting
        })
      }).catch((err) => {
        _this.setData({
          loadModal: false
        })
      })
    }
    //购买商品选择地址进入
    if (_this.data.addresstype == 2) {

      var goods = wx.getStorageSync('goodsList')
      var totalPrice = 0;
      for (var i = 0; i < goods.length; i++) {
        totalPrice = totalPrice + parseFloat(goods[i].price * goods[i].num);
      }
      totalPrice = totalPrice.toFixed(2); //合计价格
      _this.setData({
        ['navbarData.title']: '确认订单',
        goodsList: goods,
        userAddressData: wx.getStorageSync('userAddressData'),
        totalPrice: totalPrice,
        state: 3,
        pay: 1,
      })
    }
  },
  //取消
  onCancel() {
    wx.redirectTo({
      url: '/pages/index/index',
    })
  },
  //同意
  onAgree() {
    var _this = this;
    console.log(_this.data.addressid)
    // if(!_this.data.addressid){
    //   _this.setData({
    //     userAddressData: ''
    //   })
    // }

    console.log(_this.data.twoType, 11)
    //是否以前申请过
    if (_this.data.step == 1 && _this.data.UpLevelType != 1) {
      $api.getApplyDefaultData({
        login_token: wx.getStorageSync('login_token'),
      }).then((res) => {
        if (res.data.data.length <= 0) {
          if (wx.getStorageSync('id_card')) {
            _this.setData({
              ['applyShop.id_card']: wx.getStorageSync('id_card')
            })
            var id_card = wx.getStorageSync('id_card');
            var sex = id_card.substring(id_card.length - 2, id_card.length - 1);
            if (sex % 2 == 0) {
              //女
              _this.setData({
                ['applyShop.sex']: 2
              })
            } else {
              //男
              _this.setData({
                ['applyShop.sex']: 1
              })
            }
            if (wx.getStorageSync('phone')) {
              _this.setData({
                ['applyShop.phone']: wx.getStorageSync('phone')
              })
            }
            if (wx.getStorageSync('real_name')) {
              _this.setData({
                ['applyShop.real_name']: wx.getStorageSync('real_name')
              })
            }
          }
        } else {
          if (!res.data.data.join_time) {
            //获取加盟时间
            var timestamp = Date.parse(new Date());
            var date = new Date(timestamp);
            //获取年份  
            var Y = date.getFullYear();
            //获取月份  
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
            //获取当日日期 
            var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
            res.data.data.join_time = Y + '-' + M + '-' + D

          }
          console.log(res.data.data.join_time)
          _this.setData({
            ['applyShop.real_name']: res.data.data.real_name,//
            ['applyShop.sex']: res.data.data.sex,
            ['applyShop.phone']: res.data.data.phone,//
            ['applyShop.join_time']: res.data.data.join_time,
            ['applyShop.id_card']: res.data.data.id_card,//
            ['applyShop.shg_province_id']: res.data.data.shg_province_id,
            ['addressSHQ[0]']: res.data.data.shg_province_name,
            ['applyShop.shg_city_id']: res.data.data.shg_city_id,
            ['addressSHQ[1]']: res.data.data.shg_city_name,
            ['applyShop.shg_area_id']: res.data.data.shg_area_id,
            ['addressSHQ[2]']: res.data.data.shg_area_name,
            ['applyShop.shg_address']: res.data.data.shg_address,
            ['applyShop.house_owner_type']: res.data.data.house_owner_type,
            ['applyShop.lease_term']: res.data.data.lease_term,
            ['applyShop.shg_area']: res.data.data.shg_area,
            ['applyShop.is_jianying']: res.data.data.is_jianying,
            ['applyShop.has_license']: res.data.data.has_license,
            ['applyShop.license_img']: res.data.data.license_img,
            ['applyShop.house_img']: res.data.data.house_img,
            ['applyShop.door_img']: res.data.data.door_img,
            ['applyShop.house_area']: res.data.data.house_area,
            ['applyShop.nag_distance']: res.data.data.nag_distance,
            ['applyShop.social_credit_code']: res.data.data.social_credit_code,
            ['applyShop.register_date']: res.data.data.register_date,
            ['applyShop.company_name']: res.data.data.company_name,
            ['companySH[0]']: res.data.data.company_province_name,
            ['applyShop.company_provice']: res.data.data.company_provice,
            ['companySH[1]']: res.data.data.company_city_name,
            ['applyShop.company_city']: res.data.data.company_city,
            ['companySH[2]']: res.data.data.company_area_name,
            ['applyShop.company_area']: res.data.data.company_area,
            ['applyShop.company_address']: res.data.data.company_address,
            ['applyShop.shop_level']: res.data.data.shop_level,
            ['applyShop.shop_level_type']: res.data.data.shop_level ? true : false,
            default_lb_num: res.data.data.default_lb_num,
            OneInput: res.data.data.real_name_p ? false : true,
            lb_num_setting: res.data.data.lb_num_setting
          })
        }

      }).catch((err) => {

      })
    }


    _this.setData({
      state: 2,
      ['navbarData.title']: '填写信息',
      stateTypeTitle: 'https://jiujinimg.tjnanguyi.com/zhenyuanqi/tianxiexinxi.png',
      stateTypeBut: '填写个人信息',
      stateTypebuz: '个人信息',
    })

    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        duration: 500,
        scrollTop: 0
      })
    }

  },
  //地点底部弹出
  onSHG(e) {
    var _this = this;
    _this.setData({
      modalName: e.currentTarget.dataset.target,
    })
  },
  showModal(e) {
    console.log(e.currentTarget.dataset.text)
    this.setData({
      goodstext: e.currentTarget.dataset.text,
      modalName: e.currentTarget.dataset.target,

    })
  },

  //地址弹出隐藏
  hideModal(e) {
    this.setData({
      modalName: null,
      regionIndex: [0, 0, 0]
    })
  },
  //滑动时获取地址index
  onAddressIndex(e) {
    console.log(e)
    var _this = this;
    _this.setData({
      regionIndex: e.detail.value
    })
  },
  //确认地址
  confirmAddress() {
    var _this = this;
    var informationState = _this.data.informationState;
    var regionIndex = _this.data.regionIndex;
    if (informationState == 2) {
      console.log(informationState)
      console.log(_this.data.addressJson)
      _this.setData({
        ['addressSHQ[0]']: _this.data.addressJson[regionIndex[0]].provinceName,
        ['applyShop.shg_province_id']: _this.data.addressJson[regionIndex[0]].provinceId,
        ['addressSHQ[1]']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].cityName,
        ['applyShop.shg_city_id']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].cityId,
        ['addressSHQ[2]']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].region[regionIndex[2]].regionName,
        ['applyShop.shg_area_id']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].region[regionIndex[2]].regionId,
      })
      console.log(_this.data.applyShop)
    } else {
      _this.setData({
        ['companySH[0]']: _this.data.addressJson[regionIndex[0]].provinceName,
        ['applyShop.company_provice']: _this.data.addressJson[regionIndex[0]].provinceId,
        ['companySH[1]']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].cityName,
        ['applyShop.company_city']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].cityId,
        ['companySH[2]']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].region[regionIndex[2]].regionName,
        ['applyShop.company_area']: _this.data.addressJson[regionIndex[0]].city[regionIndex[1]].region[regionIndex[2]].regionId,
      })
    }
    _this.setData({
      modalName: null,
      regionIndex: [0, 0, 0]
    })

  },

  //选择房屋所有权
  onHouse(e) {
    this.setData({
      ['applyShop.house_owner_type']: e.currentTarget.dataset.house_owner_type,
      ['applyShop.lease_term']: ''
    })
  },
  //图片上传
  onUpload(e) {
    var _this = this
    _this.setData({ is_choose_img: true })
    $api.uploadImages().then((res) => {
      console.log(res)
      _this.setData({ is_choose_img: true })
      if (e.currentTarget.dataset.applyimg == 1) {
        //房本或租赁协议照片
        _this.setData({
          ['applyShop.house_img']: res.url,
        })
      } else if (e.currentTarget.dataset.applyimg == 2) {
        //营业执照照片
        _this.setData({
          ['applyShop.license_img']: res.url,
        })
      } else if (e.currentTarget.dataset.applyimg == 3) {
        //门头照片
        _this.setData({
          ['applyShop.door_img']: res.url,
        })
      }
    }).catch((err) => {
      console.log(err)
    })

  },
  //删除图片，重新上传
  onCloseImg(e) {
    var _this = this;
    var applyimg = e.currentTarget.dataset.applyimg;
    if (applyimg == 1) {
      //房本或租赁协议照片
      _this.setData({
        ['applyShop.house_img']: '',
      })
    } else if (applyimg == 2) {
      //营业执照照片
      _this.setData({
        ['applyShop.license_img']: '',
      })
    } else if (applyimg == 3) {
      //门头照片
      _this.setData({
        ['applyShop.door_img']: '',
      })
    }

  },
  //是否兼营
  onIsJy(e) {
    this.setData({
      ['applyShop.is_jianying']: e.currentTarget.dataset.isjy
    })
  },
  //是否有营业执照
  onHasLicense(e) {
    var _this = this;
    if (e.currentTarget.dataset.haslicense == 2) {
      _this.setData({
        ['applyShop.license_img']: '',
        ['applyShop.social_credit_code']: '',
        ['applyShop.register_date']: '',
        ['applyShop.company_name']: '',
        ['applyShop.company_address']: '',
        ['applyShop.company_provice']: '',
        ['applyShop.company_city']: '',
        ['applyShop.company_area']: '',
        ['companySH[0]']: '省',
        ['companySH[1]']: '市',
        ['companySH[2]']: '区'
      })
    }
    _this.setData({
      ['applyShop.has_license']: e.currentTarget.dataset.haslicense,
    })

  },
  //选择营业日期
  onLicenseTime: function (e) {
    this.setData({
      ['applyShop.register_date']: e.detail.value
    })
  },
  //填写信息的下一步
  onNext() {
    var _this = this;
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        duration: 500,
        scrollTop: 0
      })
    }
    var applyShop = _this.data.applyShop;
    console.log(applyShop)
    if (applyShop.has_license == 1) {
      if (applyShop.social_credit_code == '') {
        wx.showToast({
          title: '请填写统一社会信用代码',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.register_date == '') {
        wx.showToast({
          title: '请填写注册日期',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.company_name == '') {
        wx.showToast({
          title: '请填写商户名称',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.company_provice == '') {
        wx.showToast({
          title: '请选择所在省市',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.company_address == '') {
        wx.showToast({
          title: '请填写详细地址',
          icon: 'none',
          duration: 2000
        })
      } else {
        if (_this.data.wszl == 1) {
          _this.wsshopinfo()
          return
        }
        // 获取用户收货地址
        _this.setData({
          loadModal: true
        })

        if (_this.data.UpLevelType == 1) {
          _this.onConfirmOder()
          console.log(_this.data.UpLevelType, 123)
          return
        }
        console.log(111, 2)
        //获取首次配货产品
        $api.getRegisterGoods({
          login_token: wx.getStorageSync('login_token'),
          type: _this.data.UpLevelType == 1 ? 2 : 1,
          shop_level: _this.data.UpLevelType != 1 ? applyShop.shop_level : ''
        }).then((res) => {
          let applyShop = applyShop
          if (_this.data.UpLevelType == 1) {
            res.data.data.forEach((item) => {
              item.number = 1
            })
          } else {
            let default_lb_num = _this.data.default_lb_num
            if (default_lb_num) {
              let start = 1
              // applyShop.shop_level == 1 ? default_lb_num[1].min : applyShop.shop_level == 2 ? default_lb_num[2].min : applyShop.shop_level == 3 ? default_lb_num[3].min : 1
              res.data.data.forEach((item) => {
                item.number = start
              })
              console.log(456)
            }
            console.log(123)
          }


          console.log(res.data.data, 111)
          _this.setData({
            goodsList: res.data.data,
            loadModal: false,
            state: 3,
            ['navbarData.title']: '购买礼包',
          })
        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      }
    } else {
      if (_this.data.wszl == 1) {
        _this.wsshopinfo()
        return
      }
      // 获取用户收货地址
      _this.setData({
        loadModal: true
      })

      if (_this.data.UpLevelType == 1) {
        _this.onConfirmOder()
        console.log(_this.data.UpLevelType, 123)
        return
      }
      //获取首次配货产品
      let applyShop = _this.data.applyShop
      console.log(111, 3)
      $api.getRegisterGoods({
        login_token: wx.getStorageSync('login_token'),
        type: _this.data.UpLevelType == 1 ? 2 : 1,
        shop_level: _this.data.UpLevelType != 1 ? applyShop.shop_level : ''
      }).then((res) => {
        var totalPrice = 0;

        let default_lb_num = _this.data.default_lb_num
        let start = 1
        if (_this.data.UpLevelType == 1) {
          start = 1
          res.data.data.forEach((item) => {
            item.number = start
          })
        } else if (default_lb_num) {
          start = 1
          // applyShop.shop_level == 1 ? default_lb_num[1].min : applyShop.shop_level == 2 ? default_lb_num[2].min : applyShop.shop_level == 3 ? default_lb_num[3].min : 1
          res.data.data.forEach((item) => {
            item.number = start
          })
        }
        // for (var i = 0; i < res.data.data.length; i++) {
        //   totalPrice = totalPrice + parseFloat(res.data.data[i].price)
        //   if (_this.data.giftId == res.data.data[i].id) {
        //     res.data.data[i].number = _this.data.giftnumber
        //   }

        // }
        let giftInfoList = _this.data.giftInfoList
        res.data.data.forEach((item) => {
          item.number = start
          giftInfoList.forEach((citem) => {
            if (item.id == citem.id) {
              totalPrice = totalPrice + parseFloat(item.price)
              item.number = citem.number
              item.check = true
            }
          })
        })
        totalPrice = totalPrice.toFixed(2)
        console.log(giftInfoList)
        _this.setData({
          goodsList: res.data.data,
          loadModal: false,
          state: 3,
          ['navbarData.title']: '购买礼包',
          totalPrice: totalPrice,
          giftInfoList
        })
      }).catch((err) => {
        _this.setData({
          loadModal: false
        })
      })
    }
  },
  //选择地址
  onChoiceAddress(e) {
    var _this = this;
    wx.navigateTo({
      url: '/pages/address/list/list?choice=1&step=' + _this.data.step + '&dzy=' + _this.data.dzy + '&status=' + _this.data.status + '&UpLevelType=' + _this.data.UpLevelType + '&pzimg=' + _this.data.pzimg + '&addressid=' + _this.data.addressid,
    })
    // if (_this.data.addresstype == 1) {
    //   wx.redirectTo({
    //     url: '/pages/address/modify/modify?step=' + _this.data.step + '&dzy=' + _this.data.dzy + '&status=' + _this.data.status + '&UpLevelType=' + _this.data.UpLevelType + '&pzimg=' + _this.data.pzimg,
    //   })
    // } else {
    //   wx.navigateTo({
    //     url: '/pages/address/modify/modify?step=' + _this.data.step + '&dzy=' + _this.data.dzy + '&status=' + _this.data.status + '&UpLevelType=' + _this.data.UpLevelType + '&pzimg=' + _this.data.pzimg,
    //   })
    // }
    wx.setStorageSync('applyShop', _this.data.applyShop)
    wx.setStorageSync('wait_pay', _this.data.wait_pay)
    wx.setStorageSync('giftId', _this.data.giftId)
    wx.setStorageSync('giftnumber', _this.data.giftnumber)
    wx.setStorageSync('shop_id', _this.data.shop_id)
    // wx.setStorageSync('default_lb_num', _this.data.default_lb_num)
    wx.setStorageSync('lb_num_setting', _this.data.lb_num_setting)
    wx.setStorageSync('pay', _this.data.pay)
    wx.setStorageSync('goodsList', _this.data.goodsList)
    wx.setStorageSync('UpLevelType', _this.data.UpLevelType)
    wx.setStorageSync('pzimg', _this.data.pzimg)
    wx.setStorageSync('scType', _this.data.scType)
  },
  // 完善信息
  wsshopinfo() {
    console.log(123)
    let _this = this
    let applyShop = _this.data.applyShop
    $api.wsshopinfo({
      login_token: wx.getStorageSync('login_token'),//

      shg_province_id: applyShop.shg_province_id ? applyShop.shg_province_id : '',
      shg_city_id: applyShop.shg_city_id ? applyShop.shg_city_id : '',
      shg_area_id: applyShop.shg_area_id ? applyShop.shg_area_id : '',
      shg_address: applyShop.shg_address ? applyShop.shg_address : '',
      house_owner_type: applyShop.house_owner_type ? applyShop.house_owner_type : '',
      lease_term: applyShop.lease_term ? applyShop.lease_term : '',
      shg_area: applyShop.shg_area ? applyShop.shg_area : '',
      is_jianying: applyShop.is_jianying ? applyShop.is_jianying : '',
      has_license: applyShop.has_license ? applyShop.has_license : '',
      license_img: applyShop.license_img ? applyShop.license_img : '',
      house_img: applyShop.house_img ? applyShop.house_img : '',
      door_img: applyShop.door_img ? applyShop.door_img : '',
      house_area: applyShop.house_area ? applyShop.house_area : '',
      nag_distance: applyShop.nag_distance ? applyShop.nag_distance : '',
      shop_id: _this.data.shop_id,//
      social_credit_code: applyShop.social_credit_code ? applyShop.social_credit_code : '',
      register_date: applyShop.register_date ? applyShop.register_date : '',
      company_name: applyShop.company_name ? applyShop.company_name : '',
      company_provice: applyShop.company_provice ? applyShop.company_provice : '',
      company_city: applyShop.company_city ? applyShop.company_city : '',
      company_area: applyShop.company_area ? applyShop.company_area : '',
      company_address: applyShop.company_address ? applyShop.company_address : '',

    }).then((res) => {
      if (res.data.code == 0) {
        _this.setData({
          loadModal: false
        })
        wx.removeStorageSync('userAddressData');
        wx.removeStorageSync('giftId');
        wx.removeStorageSync('wait_pay');
        wx.removeStorageSync('applyShop');
        wx.removeStorageSync('pay');
        wx.removeStorageSync('goodsList');
        wx.removeStorageSync('address');
        wx.removeStorageSync('default_lb_num');
        wx.removeStorageSync('lb_num_setting');
        wx.removeStorageSync('giftnumber');
        wx.removeStorageSync('statusReading');
        wx.removeStorageSync('UpLevelType');
        wx.removeStorageSync('faultnum');
        wx.removeStorageSync('imglist');
        wx.removeStorageSync('pzimg');
        wx.removeStorageSync('giftInfoList');
        wx.showToast({
          title: '完善成功',
          icon: 'none',
          duration: 2000
        })
        setTimeout(() => {
          _this.out()
        }, 1000)

      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  //结算
  onConfirmOder() {
    var _this = this;
    let UpLevelType = _this.data.UpLevelType

    var buy_goods = [];
    var userAddressData = _this.data.userAddressData;
    var applyShop = _this.data.applyShop;
    var wait_pay = _this.data.wait_pay;
    var giftId = _this.data.giftId;
    var goodsList = _this.data.goodsList
    let status = wx.getStorageSync('statusReading')
    let number = 0
    let znumber = 0 
    console.log(status)
    goodsList.forEach((item) => {
      if (item.check) {
        // console.log()
        number += item.number
        if(!item.number){
          znumber++
        }
        buy_goods.push({
          "good_id": item.id,
          "num": item.number,
          lb_type: item.lb_type
        })
      }
    })
    if(znumber>0){
      wx.showToast({
        title: '请选择商品数量',
        icon: 'none',
        duration: 2000
      })
      return
    }
    console.log(goodsList)
    if (buy_goods.length == 0) {
      console.log(1)
      wx.showToast({
        title: '请选择商品',
        icon: 'none',
        duration: 2000
      })
      _this.setData({
        loadModal: false
      })
      return
    }
    if (_this.data.scType == 1) {
      // let lb_num_setting = _this.data.lb_num_setting
      // let leve1 = 0
      // let leve2 = 0
      // buy_goods.forEach((item) => {
      //   if (item.lb_type == 1) {
      //     leve1 += item.num
      //   }
      //   if (item.lb_type == 2) {
      //     leve2 += item.num
      //   }
      // })
      // let leve1info = ''
      // let leve2info = ''

      // if (lb_num_setting.xz == 1) {
      //   lb_num_setting.buy_num.forEach((citem) => {
      //     if (citem.shop_level == 1 && applyShop.shop_level == 1) {
      //       if (citem.buy_num.dzd_lb_num_max < leve1 && citem.buy_num.dzd_lb_num_max) {
      //         leve1info = '店中店商品最大购买数量为' + citem.buy_num.dzd_lb_num_max
      //       }
      //       if (citem.buy_num.dzd_lb_num_min > leve1 && citem.buy_num.dzd_lb_num_min) {
      //         leve1info = '店中店商品最小购买数量为' + citem.buy_num.dzd_lb_num_min
      //       }

      //     }
      //     if (citem.shop_level == 2 && applyShop.shop_level == 2) {
      //       if (citem.buy_num.dzd_lb_num_max < leve1 && citem.buy_num.dzd_lb_num_max) {
      //         leve1info = '店中店商品最大购买数量为' + citem.buy_num.dzd_lb_num_max
      //       }
      //       if (citem.buy_num.dzd_lb_num_min > leve1 && citem.buy_num.dzd_lb_num_min) {
      //         leve1info = '店中店商品最小购买数量为' + citem.buy_num.dzd_lb_num_min
      //       }
      //       if (citem.buy_num.ppd_lb_num_max < leve2 && citem.buy_num.ppd_lb_num_max) {
      //         leve2info = '品牌店商品最大购买数量为' + citem.buy_num.ppd_lb_num_max
      //       }
      //       if (citem.buy_num.ppd_lb_num_min > leve2 && citem.buy_num.ppd_lb_num_min) {
      //         leve2info = '品牌店商品最小购买数量为' + citem.buy_num.ppd_lb_num_min
      //       }

      //     }
      //   })
      // }
      // console.log(leve1info)
      // console.log(leve2info)
      // if (leve1info) {
      //   wx.showToast({
      //     title: leve1info,
      //     icon: 'none',
      //     duration: 2000
      //   })
      //   return
      // }
      // if (leve2info) {
      //   wx.showToast({
      //     title: leve2info,
      //     icon: 'none',
      //     duration: 2000
      //   })
      //   return
      // }
      // let default_lb_num = _this.data.default_lb_num
      // console.log(default_lb_num)
      // let start = ''
      // let end = ''
      // start = applyShop.shop_level == 1 ? default_lb_num[1].min : applyShop.shop_level == 2 ? default_lb_num[2].min : applyShop.shop_level == 3 ? default_lb_num[3].min : 1
      // end = applyShop.shop_level == 1 ? default_lb_num[1].max : applyShop.shop_level == 2 ? default_lb_num[2].max : applyShop.shop_level == 3 ? default_lb_num[3].max : 1

      // if (end < number) {
      //   wx.showToast({
      //     title: '商品总数不能超过' + end,
      //     icon: 'none',
      //     duration: 2000
      //   })
      //   return
      // }
      // if (start > number) {
      //   wx.showToast({
      //     title: '商品总数不能少于' + start,
      //     icon: 'none',
      //     duration: 2000
      //   })
      //   return
      // }
    }
    // buy_goods = buy_goods.concat({
    //   "good_id": giftId,
    //   "num": 1
    // })
    buy_goods = JSON.stringify(buy_goods)
    _this.setData({
      loadModal: true
    })
    if (userAddressData == '') {
      wx.showToast({
        title: '收货地址不能为空',
        icon: 'none',
        duration: 2000
      })
      _this.setData({
        loadModal: false
      })
    }
    //  else if (giftId == '') {
    //   wx.showToast({
    //     title: '请选择商品',
    //     icon: 'none',
    //     duration: 2000
    //   })
    //   _this.setData({
    //     loadModal: false
    //   })
    // }
    else {
      console.log(UpLevelType, _this.data.state, 1235)
      let faultnum = _this.data.faultnum ? _this.data.faultnum : {}
      if (UpLevelType == 1 && _this.data.state == 3 && !_this.data.ThreeUp) {
        console.log(applyShop, 11)
        let imglist = _this.data.imglist
        if (imglist.length == 0) {
          wx.showToast({
            title: '请上传付款凭证',
            icon: 'none',
            duration: 2000
          })
          _this.setData({
            loadModal: false
          })
          return
        }
        // let lb_num_setting = _this.data.lb_num_setting
        // let leve1 = 0
        // let leve2 = 0
        // let goodsUs = JSON.parse(buy_goods)
        // console.log(goodsUs)
        // // return
        // goodsUs.forEach((item) => {
        //   if (item.lb_type == 1) {
        //     leve1 += item.num
        //   }
        //   if (item.lb_type == 2) {
        //     leve2 += item.num
        //   }
        // })
        // let leve1info = ''
        // let leve2info = ''

        // if (lb_num_setting.xz == 1) {
        //   lb_num_setting.buy_num.forEach((citem) => {
        //     if (citem.shop_level == 1) {
        //       if (citem.buy_num.dzd_lb_num_max < leve1 && citem.buy_num.dzd_lb_num_max) {
        //         leve1info = '店中店商品最大购买数量为' + citem.buy_num.dzd_lb_num_max
        //       }
        //       if (citem.buy_num.dzd_lb_num_min > leve1 && citem.buy_num.dzd_lb_num_min) {
        //         leve1info = '店中店商品最小购买数量为' + citem.buy_num.dzd_lb_num_min
        //       }

        //     }
        //     if (citem.shop_level == 2) {
        //       if (citem.buy_num.dzd_lb_num_max < leve1 && citem.buy_num.dzd_lb_num_max) {
        //         leve1info = '店中店商品最大购买数量为' + citem.buy_num.dzd_lb_num_max
        //       }
        //       if (citem.buy_num.dzd_lb_num_min > leve1 && citem.buy_num.dzd_lb_num_min) {
        //         leve1info = '店中店商品最小购买数量为' + citem.buy_num.dzd_lb_num_min
        //       }
        //       if (citem.buy_num.ppd_lb_num_max < leve2 && citem.buy_num.ppd_lb_num_max) {
        //         leve2info = '品牌店商品最大购买数量为' + citem.buy_num.ppd_lb_num_max
        //       }
        //       if (citem.buy_num.ppd_lb_num_min > leve2 && citem.buy_num.ppd_lb_num_min) {
        //         leve2info = '品牌店商品最小购买数量为' + citem.buy_num.ppd_lb_num_min
        //       }

        //     }
        //   })
        // }
        // console.log(leve1info)
        // console.log(leve2info)
        // if (leve1info) {
        //   wx.showToast({
        //     title: leve1info,
        //     icon: 'none',
        //     duration: 2000
        //   })
        //   return
        // }
        // if (leve2info) {
        //   wx.showToast({
        //     title: leve2info,
        //     icon: 'none',
        //     duration: 2000
        //   })
        //   return
        // }
        // return
        $api.applyShopUpgrade({
          login_token: wx.getStorageSync('login_token'),//
          real_name: applyShop.real_name,//
          sex: applyShop.sex,//
          phone: applyShop.phone,//
          join_time: applyShop.join_time,//
          id_card: applyShop.id_card,//
          shop_level: applyShop.shop_level,//
          shg_province_id: applyShop.shop_level != 1 && applyShop.shg_province_id ? applyShop.shg_province_id : '',
          shg_city_id: applyShop.shop_level != 1 && applyShop.shg_city_id ? applyShop.shg_city_id : '',
          shg_area_id: applyShop.shop_level != 1 && applyShop.shg_area_id ? applyShop.shg_area_id : '',
          shg_address: applyShop.shop_level != 1 && applyShop.shg_address ? applyShop.shg_address : '',
          house_owner_type: applyShop.shop_level != 1 && applyShop.house_owner_type ? applyShop.house_owner_type : '',
          lease_term: applyShop.shop_level != 1 && applyShop.lease_term ? applyShop.lease_term : '',
          shg_area: applyShop.shop_level != 1 && applyShop.shg_area ? applyShop.shg_area : '',
          is_jianying: applyShop.shop_level != 1 && applyShop.is_jianying ? applyShop.is_jianying : '',
          has_license: applyShop.shop_level != 1 && applyShop.has_license ? applyShop.has_license : '',
          license_img: applyShop.shop_level != 1 && applyShop.license_img ? applyShop.license_img : '',
          house_img: applyShop.shop_level != 1 && applyShop.house_img ? applyShop.house_img : '',
          door_img: applyShop.shop_level != 1 && applyShop.door_img ? applyShop.door_img : '',
          house_area: applyShop.shop_level != 1 && applyShop.house_area ? applyShop.house_area : '',
          nag_distance: applyShop.shop_level != 1 && applyShop.nag_distance ? applyShop.nag_distance : '',
          buy_goods: buy_goods,//
          wait_pay: wait_pay,//
          shop_id: _this.data.shop_id,//
          social_credit_code: applyShop.shop_level != 1 && applyShop.social_credit_code ? applyShop.social_credit_code : '',
          register_date: applyShop.shop_level != 1 && applyShop.register_date ? applyShop.register_date : '',
          company_name: applyShop.shop_level != 1 && applyShop.company_name ? applyShop.company_name : '',
          company_provice: applyShop.shop_level != 1 && applyShop.company_provice ? applyShop.company_provice : '',
          company_city: applyShop.shop_level != 1 && applyShop.company_city ? applyShop.company_city : '',
          company_area: applyShop.shop_level != 1 && applyShop.company_area ? applyShop.company_area : '',
          company_address: applyShop.shop_level != 1 && applyShop.company_address ? applyShop.company_address : '',
          // buyer_name: userAddressData.buyer_name,//
          // buyer_mobile: userAddressData.buyer_mobile,//
          // province_id: userAddressData.province_id,//
          // city_id: userAddressData.city_id,//
          // area_id: userAddressData.area_id,//
          // address: userAddressData.address,//
          user_address_id: _this.data.addressid,
          offline: 1,
          imgs: JSON.stringify(imglist)

        }).then((res) => {
          console.log(res)
          if (res.data.code == 0) {
            _this.setData({
              loadModal: false
            })
            wx.removeStorageSync('userAddressData');
            wx.removeStorageSync('giftId');
            wx.removeStorageSync('wait_pay');
            wx.removeStorageSync('applyShop');
            wx.removeStorageSync('pay');
            wx.removeStorageSync('goodsList');
            wx.removeStorageSync('address');
            wx.removeStorageSync('default_lb_num');
            wx.removeStorageSync('lb_num_setting');
            wx.removeStorageSync('giftnumber');
            wx.removeStorageSync('statusReading');
            wx.removeStorageSync('UpLevelType');
            wx.removeStorageSync('faultnum');
            wx.removeStorageSync('imglist');
            wx.removeStorageSync('pzimg');
            wx.removeStorageSync('giftInfoList');
            wx.showToast({
              title:res.data.msg,
              icon: 'none',
              duration: 2000
            })
            setTimeout(()=>{
              wx.reLaunch({
                url: '/pages/index/index',
              })
            },1000)
            
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }




        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
        // if (faultnum.left_num > number && faultnum.shop_level != 3) {
        //   _this.setData({ modalName: 'withdrawModal', loadModal: false, })
        // } else {

        //   if (faultnum.shop_level == 2 || faultnum.shop_level == 3) {
        //     $api.applyShopUpgrade({
        //       login_token: wx.getStorageSync('login_token'),//
        //       real_name: applyShop.real_name,//
        //       sex: applyShop.sex,//
        //       phone: applyShop.phone,//
        //       join_time: applyShop.join_time,//
        //       id_card: applyShop.id_card,//
        //       shop_level: applyShop.shop_level,//
        //       shg_province_id: applyShop.shop_level != 1 && applyShop.shg_province_id ? applyShop.shg_province_id : '',
        //       shg_city_id: applyShop.shop_level != 1 && applyShop.shg_city_id ? applyShop.shg_city_id : '',
        //       shg_area_id: applyShop.shop_level != 1 && applyShop.shg_area_id ? applyShop.shg_area_id : '',
        //       shg_address: applyShop.shop_level != 1 && applyShop.shg_address ? applyShop.shg_address : '',
        //       house_owner_type: applyShop.shop_level != 1 && applyShop.house_owner_type ? applyShop.house_owner_type : '',
        //       lease_term: applyShop.shop_level != 1 && applyShop.lease_term ? applyShop.lease_term : '',
        //       shg_area: applyShop.shop_level != 1 && applyShop.shg_area ? applyShop.shg_area : '',
        //       is_jianying: applyShop.shop_level != 1 && applyShop.is_jianying ? applyShop.is_jianying : '',
        //       has_license: applyShop.shop_level != 1 && applyShop.has_license ? applyShop.has_license : '',
        //       license_img: applyShop.shop_level != 1 && applyShop.license_img ? applyShop.license_img : '',
        //       house_img: applyShop.shop_level != 1 && applyShop.house_img ? applyShop.house_img : '',
        //       door_img: applyShop.shop_level != 1 && applyShop.door_img ? applyShop.door_img : '',
        //       house_area: applyShop.shop_level != 1 && applyShop.house_area ? applyShop.house_area : '',
        //       nag_distance: applyShop.shop_level != 1 && applyShop.nag_distance ? applyShop.nag_distance : '',
        //       buy_goods: buy_goods,//
        //       wait_pay: wait_pay,//
        //       shop_id: _this.data.shop_id,//
        //       social_credit_code: applyShop.shop_level != 1 && applyShop.social_credit_code ? applyShop.social_credit_code : '',
        //       register_date: applyShop.shop_level != 1 && applyShop.register_date ? applyShop.register_date : '',
        //       company_name: applyShop.shop_level != 1 && applyShop.company_name ? applyShop.company_name : '',
        //       company_provice: applyShop.shop_level != 1 && applyShop.company_provice ? applyShop.company_provice : '',
        //       company_city: applyShop.shop_level != 1 && applyShop.company_city ? applyShop.company_city : '',
        //       company_area: applyShop.shop_level != 1 && applyShop.company_area ? applyShop.company_area : '',
        //       company_address: applyShop.shop_level != 1 && applyShop.company_address ? applyShop.company_address : '',
        //       // buyer_name: userAddressData.buyer_name,//
        //       // buyer_mobile: userAddressData.buyer_mobile,//
        //       // province_id: userAddressData.province_id,//
        //       // city_id: userAddressData.city_id,//
        //       // area_id: userAddressData.area_id,//
        //       // address: userAddressData.address,//
        //       user_address_id: _this.data.addressid,
        //       offline: 1,
        //       imgs: JSON.stringify(imglist)

        //     }).then((res) => {
        //       console.log(res)
        //       if (res.data.code == 0) {
        //         _this.setData({
        //           loadModal: false
        //         })
        //         wx.removeStorageSync('userAddressData');
        //         wx.removeStorageSync('giftId');
        //         wx.removeStorageSync('wait_pay');
        //         wx.removeStorageSync('applyShop');
        //         wx.removeStorageSync('pay');
        //         wx.removeStorageSync('goodsList');
        //         wx.removeStorageSync('address');
        //         wx.removeStorageSync('default_lb_num');
        //         wx.removeStorageSync('lb_num_setting');
        //         wx.removeStorageSync('giftnumber');
        //         wx.removeStorageSync('statusReading');
        //         wx.removeStorageSync('UpLevelType');
        //         wx.removeStorageSync('faultnum');
        //         wx.removeStorageSync('imglist');
        //         wx.removeStorageSync('pzimg');
        //         wx.removeStorageSync('giftInfoList');
        //         wx.showToast({
        //           title: '修改成功',
        //           icon: 'none',
        //           duration: 2000
        //         })
        //         wx.reLaunch({
        //           url: '/pages/index/index',
        //         })
        //       } else {
        //         wx.showToast({
        //           title: res.data.msg,
        //           icon: 'none',
        //           duration: 2000
        //         })
        //       }




        //     }).catch((err) => {
        //       _this.setData({
        //         loadModal: false
        //       })
        //     })
        //   } else {
        //     _this.setData({ informationState: 2, loadModal: false, state: 2 })
        //   }
        // }
        return
      }
      console.log(5, 888)
      if (status == 20 || status == 21) {
        console.log(9, 888)
        let imglist = _this.data.imglist
        if (imglist.length == 0) {
          wx.showToast({
            title: '请上传付款凭证',
            icon: 'none',
            duration: 2000
          })
          _this.setData({
            loadModal: false
          })
          return
        }
        $api.editShopApply({
          login_token: wx.getStorageSync('login_token'),
          shop_id: _this.data.shop_id,
          real_name: applyShop.real_name,
          sex: applyShop.sex,
          phone: applyShop.phone,
          join_time: applyShop.join_time,
          id_card: applyShop.id_card,
          shg_province_id: applyShop.shg_province_id,
          shg_city_id: applyShop.shg_city_id,
          shg_area_id: applyShop.shg_area_id,
          shg_address: applyShop.shg_address,
          house_owner_type: applyShop.house_owner_type,
          lease_term: applyShop.lease_term,
          shg_area: applyShop.shg_area,
          is_jianying: applyShop.is_jianying,
          has_license: applyShop.has_license,
          license_img: applyShop.license_img,
          house_img: applyShop.house_img,
          door_img: applyShop.door_img,
          house_area: applyShop.house_area,
          nag_distance: applyShop.nag_distance,
          social_credit_code: applyShop.social_credit_code,
          register_date: applyShop.register_date,
          company_name: applyShop.company_name,
          company_provice: applyShop.company_provice,
          company_city: applyShop.company_city,
          company_area: applyShop.company_area,
          company_address: applyShop.company_address,
          fukuan_imgs: JSON.stringify(imglist)
        }).then((res) => {
          _this.setData({
            loadModal: false
          })
          wx.removeStorageSync('address')

          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
          setTimeout(function () {
            wx.reLaunch({
              url: '/pages/index/index',
            })
          }, 1000)
        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      } else if (_this.data.UpLevelType == 1 || faultnum.shop_level == 1 || faultnum.shop_level == 3) {
        let imglist = _this.data.imglist
        console.log(2.888)
        if (imglist.length == 0) {
          wx.showToast({
            title: '请上传付款凭证',
            icon: 'none',
            duration: 2000
          })
          _this.setData({
            loadModal: false
          })
          return
        }
        $api.applyShopUpgrade({
          login_token: wx.getStorageSync('login_token'),//
          real_name: applyShop.real_name,//
          sex: applyShop.sex,//
          phone: applyShop.phone,//
          join_time: applyShop.join_time,//
          id_card: applyShop.id_card,//
          shop_level: applyShop.shop_level,//
          shg_province_id: applyShop.shop_level != 1 && applyShop.shg_province_id ? applyShop.shg_province_id : '',
          shg_city_id: applyShop.shop_level != 1 && applyShop.shg_city_id ? applyShop.shg_city_id : '',
          shg_area_id: applyShop.shop_level != 1 && applyShop.shg_area_id ? applyShop.shg_area_id : '',
          shg_address: applyShop.shop_level != 1 && applyShop.shg_address ? applyShop.shg_address : '',
          house_owner_type: applyShop.shop_level != 1 && applyShop.house_owner_type ? applyShop.house_owner_type : '',
          lease_term: applyShop.shop_level != 1 && applyShop.lease_term ? applyShop.lease_term : '',
          shg_area: applyShop.shop_level != 1 && applyShop.shg_area ? applyShop.shg_area : '',
          is_jianying: applyShop.shop_level != 1 && applyShop.is_jianying ? applyShop.is_jianying : '',
          has_license: applyShop.shop_level != 1 && applyShop.has_license ? applyShop.has_license : '',
          license_img: applyShop.shop_level != 1 && applyShop.license_img ? applyShop.license_img : '',
          house_img: applyShop.shop_level != 1 && applyShop.house_img ? applyShop.house_img : '',
          door_img: applyShop.shop_level != 1 && applyShop.door_img ? applyShop.door_img : '',
          house_area: applyShop.shop_level != 1 && applyShop.house_area ? applyShop.house_area : '',
          nag_distance: applyShop.shop_level != 1 && applyShop.nag_distance ? applyShop.nag_distance : '',
          buy_goods: buy_goods,//
          wait_pay: wait_pay,//
          shop_id: _this.data.shop_id,//
          social_credit_code: applyShop.shop_level != 1 && applyShop.social_credit_code ? applyShop.social_credit_code : '',
          register_date: applyShop.shop_level != 1 && applyShop.register_date ? applyShop.register_date : '',
          company_name: applyShop.shop_level != 1 && applyShop.company_name ? applyShop.company_name : '',
          company_provice: applyShop.shop_level != 1 && applyShop.company_provice ? applyShop.company_provice : '',
          company_city: applyShop.shop_level != 1 && applyShop.company_city ? applyShop.company_city : '',
          company_area: applyShop.shop_level != 1 && applyShop.company_area ? applyShop.company_area : '',
          company_address: applyShop.shop_level != 1 && applyShop.company_address ? applyShop.company_address : '',
          // buyer_name: userAddressData.buyer_name,//
          // buyer_mobile: userAddressData.buyer_mobile,//
          // province_id: userAddressData.province_id,//
          // city_id: userAddressData.city_id,//
          // area_id: userAddressData.area_id,//
          // address: userAddressData.address,//
          user_address_id: _this.data.addressid,
          offline: 1,
          imgs: JSON.stringify(imglist)

        }).then((res) => {
          console.log(res)
          if (res.data.code == 0) {
            _this.setData({
              loadModal: false
            })
            wx.removeStorageSync('userAddressData');
            wx.removeStorageSync('giftId');
            wx.removeStorageSync('wait_pay');
            wx.removeStorageSync('applyShop');
            wx.removeStorageSync('pay');
            wx.removeStorageSync('goodsList');
            wx.removeStorageSync('address');
            wx.removeStorageSync('default_lb_num');
            wx.removeStorageSync('lb_num_setting');
            wx.removeStorageSync('giftnumber');
            wx.removeStorageSync('statusReading');
            wx.removeStorageSync('UpLevelType');
            wx.removeStorageSync('faultnum');
            wx.removeStorageSync('imglist');
            wx.removeStorageSync('pzimg');
            wx.removeStorageSync('giftInfoList');
            wx.showToast({
              title:res.data.msg,
              icon: 'none',
              duration: 2000
            })
            wx.reLaunch({
              url: '/pages/index/index',
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }




        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      } else {
        console.log(applyShop, 888)
        // return
        let imglist = _this.data.imglist
        if (imglist.length == 0) {
          wx.showToast({
            title: '请上传付款凭证',
            icon: 'none',
            duration: 2000
          })
          _this.setData({
            loadModal: false
          })
          return
        }
        $api.applyShop({
          login_token: wx.getStorageSync('login_token'),//
          real_name: applyShop.real_name,//
          sex: applyShop.sex,//
          phone: applyShop.phone,//
          join_time: applyShop.join_time,//
          id_card: applyShop.id_card,//
          shop_level: applyShop.shop_level,//
          shg_province_id: applyShop.shop_level != 1 && applyShop.shg_province_id ? applyShop.shg_province_id : '',
          shg_city_id: applyShop.shop_level != 1 && applyShop.shg_city_id ? applyShop.shg_city_id : '',
          shg_area_id: applyShop.shop_level != 1 && applyShop.shg_area_id ? applyShop.shg_area_id : '',
          shg_address: applyShop.shop_level != 1 && applyShop.shg_address ? applyShop.shg_address : '',
          house_owner_type: applyShop.shop_level != 1 && applyShop.house_owner_type ? applyShop.house_owner_type : '',
          lease_term: applyShop.shop_level != 1 && applyShop.lease_term ? applyShop.lease_term : '',
          shg_area: applyShop.shop_level != 1 && applyShop.shg_area ? applyShop.shg_area : '',
          is_jianying: applyShop.shop_level != 1 && applyShop.is_jianying ? applyShop.is_jianying : '',
          has_license: applyShop.shop_level != 1 && applyShop.has_license ? applyShop.has_license : '',
          license_img: applyShop.shop_level != 1 && applyShop.license_img ? applyShop.license_img : '',
          house_img: applyShop.shop_level != 1 && applyShop.house_img ? applyShop.house_img : '',
          door_img: applyShop.shop_level != 1 && applyShop.door_img ? applyShop.door_img : '',
          house_area: applyShop.shop_level != 1 && applyShop.house_area ? applyShop.house_area : '',
          nag_distance: applyShop.shop_level != 1 && applyShop.nag_distance ? applyShop.nag_distance : '',
          buy_goods: buy_goods,//
          wait_pay: wait_pay,//
          shop_id: _this.data.shop_id,//
          social_credit_code: applyShop.shop_level != 1 && applyShop.social_credit_code ? applyShop.social_credit_code : '',
          register_date: applyShop.shop_level != 1 && applyShop.register_date ? applyShop.register_date : '',
          company_name: applyShop.shop_level != 1 && applyShop.company_name ? applyShop.company_name : '',
          company_provice: applyShop.shop_level != 1 && applyShop.company_provice ? applyShop.company_provice : '',
          company_city: applyShop.shop_level != 1 && applyShop.company_city ? applyShop.company_city : '',
          company_area: applyShop.shop_level != 1 && applyShop.company_area ? applyShop.company_area : '',
          company_address: applyShop.shop_level != 1 && applyShop.company_address ? applyShop.company_address : '',
          // buyer_name: userAddressData.buyer_name,//
          // buyer_mobile: userAddressData.buyer_mobile,//
          // province_id: userAddressData.province_id,//
          // city_id: userAddressData.city_id,//
          // area_id: userAddressData.area_id,//
          // address: userAddressData.address,//
          user_address_id: _this.data.addressid,
          offline: 1,
          fukuan_imgs: JSON.stringify(imglist)

        }).then((res) => {
          console.log(res)
          _this.setData({
            loadModal: false
          })
          wx.removeStorageSync('userAddressData');
          wx.removeStorageSync('giftId');
          wx.removeStorageSync('wait_pay');
          wx.removeStorageSync('applyShop');
          wx.removeStorageSync('pay');
          wx.removeStorageSync('goodsList');
          wx.removeStorageSync('address');
          wx.removeStorageSync('default_lb_num');
          wx.removeStorageSync('lb_num_setting');
          wx.removeStorageSync('giftnumber');
          wx.removeStorageSync('statusReading');
          wx.removeStorageSync('UpLevelType');
          wx.removeStorageSync('faultnum');
          wx.removeStorageSync('imglist');
          wx.removeStorageSync('pzimg');
          wx.removeStorageSync('giftInfoList');
          if (status == 20 || status == 21) {
            wx.reLaunch({
              url: 'pages/index/index',
            })
          } else {
            wx.reLaunch({
              url: '/pages/details/details?shop_id=' + res.data.data.shop_id,
            })
          }


        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      }

    }

  },
  hideModal(e) {
    this.setData({
      modalName: null,
    })
  },
  onCancleShopInfo(e) {
    let faultnum = this.data.faultnum
    if (faultnum.shop_level == 2 || faultnum.shop_level == 1) {
      this.setData({ ThreeUp: true })
      this.onConfirmOder()
    } else {
      this.setData({ informationState: 2, state: 2 })
    }

  },
  //修改信息确认提交
  onSubmit() {
    var _this = this;
    var applyShop = _this.data.applyShop;
    var shop_id = _this.data.shop_id;
    if (applyShop.has_license == 1) {
      if (applyShop.social_credit_code == '') {
        wx.showToast({
          title: '请填写统一社会信用代码',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.register_date == '') {
        wx.showToast({
          title: '请填写注册日期',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.company_name == '') {
        wx.showToast({
          title: '请填写商户名称',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.company_provice == '') {
        wx.showToast({
          title: '请选择所在省市',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.company_address == '') {
        wx.showToast({
          title: '请填写详细地址',
          icon: 'none',
          duration: 2000
        })
      } else {
        //0==不是待支付
        if (_this.data.dzy == 0) {
          _this.setData({
            loadModal: true
          })
          $api.editShopApply({
            login_token: wx.getStorageSync('login_token'),
            shop_id: shop_id,
            real_name: applyShop.real_name,
            sex: applyShop.sex,
            phone: applyShop.phone,
            join_time: applyShop.join_time,
            id_card: applyShop.id_card,
            shg_province_id: applyShop.shg_province_id,
            shg_city_id: applyShop.shg_city_id,
            shg_area_id: applyShop.shg_area_id,
            shg_address: applyShop.shg_address,
            house_owner_type: applyShop.house_owner_type,
            lease_term: applyShop.lease_term,
            shg_area: applyShop.shg_area,
            is_jianying: applyShop.is_jianying,
            has_license: applyShop.has_license,
            license_img: applyShop.license_img,
            house_img: applyShop.house_img,
            door_img: applyShop.door_img,
            house_area: applyShop.house_area,
            nag_distance: applyShop.nag_distance,
            social_credit_code: applyShop.social_credit_code,
            register_date: applyShop.register_date,
            company_name: applyShop.company_name,
            company_provice: applyShop.company_provice,
            company_city: applyShop.company_city,
            company_area: applyShop.company_area,
            company_address: applyShop.company_address,
          }).then((res) => {
            _this.setData({
              loadModal: false
            })
            wx.removeStorageSync('address')
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
            setTimeout(function () {
              wx.navigateBack({
                delta: 1,
              })
            }, 1500)
          }).catch((err) => {
            _this.setData({
              loadModal: false
            })
          })
        } else {
          _this.setData({
            state: 3,
            ['navbarData.title']: '购买礼包',

          })
        }
      }
    } else {
      //0==不是待支付
      if (_this.data.dzy == 0) {
        _this.setData({
          loadModal: true
        })

        $api.editShopApply({
          login_token: wx.getStorageSync('login_token'),
          shop_id: shop_id,
          real_name: applyShop.real_name,
          sex: applyShop.sex,
          phone: applyShop.phone,
          join_time: applyShop.join_time,
          id_card: applyShop.id_card,
          shg_province_id: applyShop.shg_province_id,
          shg_city_id: applyShop.shg_city_id,
          shg_area_id: applyShop.shg_area_id,
          shg_address: applyShop.shg_address,
          house_owner_type: applyShop.house_owner_type,
          lease_term: applyShop.lease_term,
          shg_area: applyShop.shg_area,
          is_jianying: applyShop.is_jianying,
          has_license: applyShop.has_license,
          license_img: applyShop.license_img,
          house_img: applyShop.house_img,
          door_img: applyShop.door_img,
          house_area: applyShop.house_area,
          nag_distance: applyShop.nag_distance,
          social_credit_code: applyShop.social_credit_code,
          register_date: applyShop.register_date,
          company_name: applyShop.company_name,
          company_provice: applyShop.company_provice,
          company_city: applyShop.company_city,
          company_area: applyShop.company_area,
          company_address: applyShop.company_address,
        }).then((res) => {
          _this.setData({
            loadModal: false
          })
          wx.removeStorageSync('address')
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
          setTimeout(function () {
            wx.navigateBack({
              delta: 1,
            })
          }, 1500)
        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      } else {
        _this.setData({
          state: 3,
          ['navbarData.title']: '购买礼包',

        })
      }
    }
  },
  //确认订单去支付
  onWxPay() {
    var _this = this;
    if (!_this.data.userAddressData) {
      wx.showToast({
        title: '请添加收货地址',
        icon: 'none',
        duration: 2000
      })
    } else {
      var buy_goods = [];
      for (var i = 0; i < _this.data.goodsList.length; i++) {
        buy_goods = buy_goods.concat({
          "good_id": _this.data.goodsList[i].id,
          "num": _this.data.goodsList[i].num
        })
      }
      buy_goods = JSON.stringify(buy_goods)
      // wx.navigateTo({
      //   url: '/pages/Payment/Payment?buy_goods=' + buy_goods,
      // })

      _this.setData({
        loadModal: true,
        payTime: 1
      })
      _this.TwopayTime()
      console.log(_this.data.zbgoodsType)
      // return
      var user_address = wx.getStorageSync('address')
      if (_this.data.zbgoodsType == 1) {
        $api.liveconfirmorder({
          login_token: wx.getStorageSync('login_token'),
          buy_goods: buy_goods,
          user_address_id: _this.data.addressid,
          type: _this.data.is_register
        }).then((res) => {
          console.log(res)
          var order_id = res.data.order_id;
          _this.setData({
            loadModal: false,
            payTime: 1
          })
          wx.navigateTo({
            url: '/pages/Payment/Payment?order_id=' + order_id,
          })
          return

        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      } else {
        $api.comfirmOrdernew({
          login_token: wx.getStorageSync('login_token'),
          buy_goods: buy_goods,
          user_address_id: _this.data.addressid,
          // buyer_name: user_address.buyer_name,
          // buyer_mobile: user_address.buyer_mobile,
          // province_id: user_address.province_id,
          // city_id: user_address.city_id,
          // area_id: user_address.area_id,
          // address: user_address.address,
          type: _this.data.is_register
        }).then((res) => {
          console.log(res)
          var order_id = res.data.order_id;
          _this.setData({
            loadModal: false,
            payTime: 1
          })
          wx.navigateTo({
            url: '/pages/Payment/Payment?order_id=' + order_id,
          })
          return
          //支付
          wx.login({
            success(res) {
              console.log(res)
              $api.getOpenidAppPay({
                js_code: res.code
              }).then((res) => {
                console.log(res.data, 66)
                if (res.data.code == 0) {
                  var openid = res.data.data.openid;
                  $api.appPayFunc({
                    login_token: wx.getStorageSync('login_token'),//用户登录token
                    order_id: order_id,//订单id
                    pay_type: 4,//支付类型 4 第三方微信支付 
                    is_fp: 0,//是否分批付款 0否 1是
                    // fp_money: options.fp_money,//付款金额
                    sf_openid: openid,//三方支付微信支付的openid

                  }).then((res) => {
                    if (res.data.code == 0) {
                      var payData = JSON.parse(res.data.data.sfwxdata.expend.pay_info);
                      var packages = payData.package;
                      var timeStamp = payData.timeStamp;
                      wx.requestPayment({
                        timeStamp: timeStamp.toString(),
                        nonceStr: payData.nonceStr,
                        package: packages,
                        signType: payData.signType,
                        paySign: payData.paySign,
                        success(res) {
                          console.log(res)
                          //支付成功
                          wx.removeStorageSync('address')
                          wx.redirectTo({
                            url: '/pages/order/order?type=4',
                          })
                        },
                        fail(res) {
                          console.log(res)
                          wx.redirectTo({
                            url: '/pages/order/order?type=4',
                          })
                        },
                        complete() {
                          wx.removeStorageSync('userAddressData');
                          wx.removeStorageSync('giftId');
                          wx.removeStorageSync('wait_pay');
                          wx.removeStorageSync('applyShop');
                          wx.removeStorageSync('pay');
                          wx.removeStorageSync('goodsList');
                          wx.removeStorageSync('default_lb_num');
                          wx.removeStorageSync('giftnumber');
                          wx.removeStorageSync('statusReading');
                          wx.removeStorageSync('UpLevelType');
                          wx.removeStorageSync('faultnum');
                          wx.removeStorageSync('imglist');
                          wx.removeStorageSync('pzimg');
                          wx.removeStorageSync('giftInfoList');
                        }
                      })

                    } else {
                      wx.showToast({
                        title: res.data.message,
                        icon: 'none',
                        duration: 2000
                      })
                    }
                  })
                }
              })
            }
          })
          // $api.wxPay({
          //   login_token: wx.getStorageSync('login_token'),
          //   order_id: order_id
          // }).then((res) => {
          //   var wxPay = res.data.data;
          //   var timeStamp = wxPay.timeStamp
          //   wx.requestPayment({
          //     timeStamp: timeStamp.toString(),
          //     nonceStr: wxPay.nonceStr,
          //     package: wxPay.package,
          //     signType: wxPay.signType,
          //     paySign: wxPay.paySign,
          //     success(res) {
          //       console.log(res)
          //       wx.removeStorageSync('address')
          //       wx.redirectTo({
          //         url: '/pages/order/order?type=4',
          //       })
          //     },
          //     fail(res) {
          //       console.log(res)
          //       wx.redirectTo({
          //         url: '/pages/order/order?type=4',
          //       })
          //     },
          //     complete() {
          //       wx.removeStorageSync('userAddressData');
          //       wx.removeStorageSync('giftId');
          //       wx.removeStorageSync('wait_pay');
          //       wx.removeStorageSync('applyShop');
          //       wx.removeStorageSync('pay');
          //       wx.removeStorageSync('goodsList');
          //       wx.removeStorageSync('default_lb_num');
          //       wx.removeStorageSync('giftnumber');
          //       wx.removeStorageSync('statusReading');
          //       wx.removeStorageSync('UpLevelType');
          //       wx.removeStorageSync('faultnum');
          //       wx.removeStorageSync('imglist');
          //       wx.removeStorageSync('pzimg');
          //     }
          //   })
          // }).catch((err) => {
          //   _this.setData({
          //     loadModal: false
          //   })
          // })

        }).catch((err) => {
          _this.setData({
            loadModal: false
          })
        })
      }

    }




  },
  // 
  TwopayTime() {
    let _this = this
    let payTime = _this.data.payTime
    console.log(payTime)
    if (payTime < 5) {
      setTimeout(() => {
        payTime++;
        _this.setData({ payTime })
        _this.TwopayTime()
      }, 1000)
    } else {
      _this.setData({ payTime: 0 })
    }
  },
  //查看图片
  onSeeImage(e) {
    wx.previewImage({
      current: e.currentTarget.dataset.url,
      urls: [e.currentTarget.dataset.url]
    })
  },
  //填写信息中信息切换
  onInformation(e) {
    var _this = this;
    var informationState = e.currentTarget.dataset.informationstate;
    var applyShop = _this.data.applyShop;
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; //11位手机号码正则
    if (informationState == 2) {
      //个人信息下一步
      if (applyShop.phone == '') {
        wx.showToast({
          title: '请输入手机号',
          icon: 'none',
          duration: 2000
        })
      }
      //  else if (!reg_tel.test(applyShop.phone)) {
      //   wx.showToast({
      //     title: '请输入正确的手机号',
      //     icon: 'none',
      //     duration: 2000
      //   })
      // } 
      else if (!applyShop.shop_level && _this.data.UpLevelType != 1) {
        console.log(applyShop.shop_level)
        wx.showToast({
          title: '请选择店铺等级',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.real_name) {
        console.log(applyShop)
        wx.showToast({
          title: '请输入姓名',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.id_card) {
        wx.showToast({
          title: '请输入身份证号',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.sex) {
        wx.showToast({
          title: '请选择性别',
          icon: 'none',
          duration: 2000
        })
      } else {
        if (_this.data.UpLevelType) {
          let goodsList = _this.data.goodsList
            goodsList.forEach((item) => {
              item.number = 1
            })
            _this.setData({
              goodsList
            })
          // $api.getupgradedefaultnum({
          //   login_token: wx.getStorageSync('login_token'),
          //   shop_id: _this.data.shop_id,
          //   // shop_level: applyShop.shop_level
          // }).then((res) => {
          //   console.log(res.data.data, 111)
          //   // res.data.data.shop_level = 3
          //   wx.setStorageSync('faultnum', res.data.data)
          //   wx.setStorageSync('lb_num_setting', res.data.data.lb_num_setting)
          //   let goodsList = _this.data.goodsList
          //   goodsList.forEach((item) => {
          //     item.number = 1
          //   })
          //   _this.setData({
          //     faultnum: res.data.data,
          //     lb_num_setting: res.data.data.lb_num_setting,
          //     goodsList
          //   })
          // }).catch((err) => {
          // })
        }
        if (_this.data.is_sj == 1) {
          _this.setData({
            informationState: 2,
            stateTypeBut: '填写店铺信息',
            stateTypebuz: '店铺信息',
          })
        } else if (_this.data.UpLevelType == 1) {
          console.log(1111)
          _this.setData({
            state: 3,
          })
        } else if (applyShop.shop_level == 1) {
          console.log(2222)
          _this.onNext()
        } else {
          _this.setData({
            informationState: 2,
            stateTypeBut: '填写店铺信息',
            stateTypebuz: '店铺信息',
          })
        }

      }
    } else if (informationState == 3) {
      //店铺申请信息
      if (!applyShop.shg_province_id) {
        wx.showToast({
          title: '请选择臻元气地址',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.shg_address) {
        wx.showToast({
          title: '请选择详细地址',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.house_owner_type) {
        wx.showToast({
          title: '请选择房屋所有权',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.house_owner_type == 2 && !applyShop.lease_term) {
        wx.showToast({
          title: '请填写租赁期限',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.shg_area) {
        wx.showToast({
          title: '请填写臻元气面积',
          icon: 'none',
          duration: 2000
        })
      } else if (applyShop.is_jianying == 0) {
        wx.showToast({
          title: '请选择是否兼营',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.house_area) {
        wx.showToast({
          title: '请填写房屋总面积',
          icon: 'none',
          duration: 2000
        })
      } else if (!applyShop.nag_distance) {
        wx.showToast({
          title: '请填写臻元气申请地点与最近的臻元气的距离',
          icon: 'none',
          duration: 2000
        })
      } else {
        _this.setData({
          informationState: 3,
          stateTypeBut: '填写店铺信息',
          stateTypebuz: '店铺信息',
          ['applyShop.has_license']: 1
        })
      }
      console.log(applyShop, 33)
    }

  },
  //获取店铺信息
  onShopInformation(e) {
    var _this = this;
    console.log(e, 123)
    var id = e.currentTarget.dataset.id;
    if (id == 1) {
      //获取手机号
      _this.setData({
        ['applyShop.phone']: e.detail.value
      })

    } else if (id == 2) {
      //获取详细地址
      _this.setData({
        ['applyShop.shg_address']: e.detail.value
      })
    } else if (id == 3) {
      //获取臻元气面积
      _this.setData({
        ['applyShop.shg_area']: e.detail.value
      })
    } else if (id == 4) {
      //租赁期限
      _this.setData({
        ['applyShop.lease_term']: e.detail.value
      })
    } else if (id == 5) {
      //获取房屋总面积
      _this.setData({
        ['applyShop.house_area']: e.detail.value
      })
    } else if (id == 6) {
      //地点离最近暖艾馆距离
      _this.setData({
        ['applyShop.nag_distance']: e.detail.value
      })
    } else if (id == 7) {
      //统一社会信用代码
      _this.setData({
        ['applyShop.social_credit_code']: e.detail.value
      })
    } else if (id == 8) {
      //注册日期
      _this.setData({
        ['applyShop.register_date']: e.detail.value
      })
    } else if (id == 9) {
      //商户名称
      _this.setData({
        ['applyShop.company_name']: e.detail.value
      })
    } else if (id == 10) {
      //商户详细地址
      _this.setData({
        ['applyShop.company_address']: e.detail.value
      })
    }
    console.log(_this.data.applyShop)
  },
  //商品详情的展开折叠
  onGoodsListProduct() {
    this.setData({
      goodsListProduct: !(this.data.goodsListProduct)
    })
  },
  //选择购买的礼包
  onGiftBag(e) {
    var _this = this;
    console.log(e)
    let status = wx.getStorageSync('statusReading')
    if (_this.data.dzy == 0 && !status) {
      if (_this.data.pay != 1) {
        if (_this.data.giftId == e.currentTarget.dataset.id) {
          _this.setData({
            giftId: '',
            giftList: [],
            goodsListProduct: false,
            totalPrice: '0.00'
          })
          wx.setStorageSync('giftId', '')
        } else {
          let goodsList = _this.data.goodsList
          let giftInfoList = []
          goodsList.forEach((item) => {
            if (e.currentTarget.dataset.id == item.id) {
              item.check = !item.check
            }
            if (item.check) {
              giftInfoList.push(item)
            }
          })
          console.log(goodsList)
          _this.setData({ goodsList, giftInfoList })
          wx.setStorageSync('giftInfoList', giftInfoList)
          // for (var i = 0; i < _this.data.goodsList.length; i++) {
          //   if (e.currentTarget.dataset.id == _this.data.goodsList[i].id) {
          //     console.log(_this.data.goodsList[i].price)
          //     _this.setData({
          //       loadModal: true,
          //       giftId: e.currentTarget.dataset.id,
          //       giftnumber: _this.data.goodsList[i].number,
          //       goodsListProduct: true,
          //       totalPrice: _this.data.goodsList[i].price,
          //     })
          //     wx.setStorageSync('giftId', e.currentTarget.dataset.id)
          //     wx.setStorageSync('giftnumber', _this.data.goodsList[i].number)
          //     $api.getGoodsProducts({
          //       login_token: wx.getStorageSync('login_token'),
          //       good_id: e.currentTarget.dataset.id
          //     }).then((res) => {
          //       console.log(res.data.data)
          //       _this.setData({
          //         giftList: res.data.data,
          //         loadModal: false,
          //       })
          //     }).catch((err) => {
          //       _this.setData({
          //         loadModal: false
          //       })
          //     })
          //   }
          // }
        }
      }
    }


  },
  // 选择商品数量
  onnumber(e) {
    console.log(e, 111)
    let _this = this
    // if (_this.data.twoType == 1 && _this.data.ptType != 1) {
    //   return
    // }
    if (_this.data.zbgoodsType == 1) {
      return
    }
    let applyShop = _this.data.applyShop
    let goodsList = _this.data.goodsList
    let twoType = _this.data.twoType
    let giftInfoList = []
    if (twoType == 1) {
      let buy_goods = []
      goodsList.forEach((item) => {
        item.num = item.num ? item.num : 0
        if (e.currentTarget.dataset.id == item.id) {
          if (e.currentTarget.dataset.type == 'jian' && item.num > 0) {
            item.num--;
          } else if (e.currentTarget.dataset.type == 'jia') {
            item.num++;
          }
          item.num = item.num ? item.num : 1;
          wx.setStorageSync('giftId', e.currentTarget.dataset.id)
          wx.setStorageSync('giftnumber', item.num)
        }
        if (item.check) {
          giftInfoList.push(item)
        }
        buy_goods.push({
          good_id: item.id,
          num: item.num,
        })
      })
      $api.getferightfee({
        login_token: wx.getStorageSync('login_token'),
        buy_goods: JSON.stringify(buy_goods),
        type: _this.data.is_register,
        is_live: _this.data.zbgoodsType ? 1 : 0
      }).then((res) => {
        let fee = res.data.data
        wx.setStorageSync('giftInfoList', giftInfoList)
        console.log(goodsList, 666)
        var totalPrice = 0;
        for (var i = 0; i < goodsList.length; i++) {
          totalPrice = totalPrice + parseFloat(goodsList[i].price * goodsList[i].num);
        }
        console.log(totalPrice.toFixed(2), Number(fee), 888)
        totalPrice = Number(totalPrice.toFixed(2)) + Number(fee); //合计价格
        _this.setData({ goodsList, totalPrice, giftInfoList, fee })
      }).catch((err) => {
        _this.setData({
          loadModal: false
        })
      })

      return
    }
    console.log(1235)
    if (_this.data.dzy) {
      return
    }
    let default_lb_num = _this.data.default_lb_num
    console.log(default_lb_num)
    let start = ''
    let end = ''
    console.log(start)
    if (_this.data.UpLevelType == 1) {
      start = 1
      end = 999
    } else {
      start = 1
      // applyShop.shop_level == 1 ? default_lb_num[1].min : applyShop.shop_level == 2 ? default_lb_num[2].min : applyShop.shop_level == 3 ? default_lb_num[3].min : 1
      end = 1
      // applyShop.shop_level == 1 ? default_lb_num[1].max : applyShop.shop_level == 2 ? default_lb_num[2].max : applyShop.shop_level == 3 ? default_lb_num[3].max : 1

    }
    let giftnumber = 0
    goodsList.forEach((item) => {
      item.number = item.number ? item.number : 0
      if (e.currentTarget.dataset.id == item.id) {
        if (e.currentTarget.dataset.type == 'jian' && item.number > 0) {
          item.number--;
        } else if (e.currentTarget.dataset.type == 'jia') {
          item.number++;
        }
        // if (item.number < start) {
        //   wx.showToast({
        //     title: '已达最小购买数量',
        //     icon: 'none',
        //     duration: 2000
        //   })
        // }
        // if (item.number > end) {
        //   wx.showToast({
        //     title: '已达最大购买数量',
        //     icon: 'none',
        //     duration: 2000
        //   })
        // }
        item.number = item.number ? item.number : 1
        // < start ? start : item.number > end ? end : item.number
        giftnumber = item.number ? item.number : 1

        wx.setStorageSync('giftId', e.currentTarget.dataset.id)
        wx.setStorageSync('giftnumber', giftnumber)

      }
      if (item.check) {
        giftInfoList.push(item)
      }
    })
    wx.setStorageSync('giftInfoList', giftInfoList)
    console.log(goodsList)
    _this.setData({ goodsList, giftId: e.currentTarget.dataset.id, giftnumber, giftInfoList })
  },
  // 选择等级
  onshoplevel(e) {
    let _this = this
    let applyShop = _this.data.applyShop
    if (applyShop.shop_level_type) {
      return
    }
    applyShop.shop_level = e.currentTarget.dataset.level
    _this.setData({ applyShop })
  },
  onOneInput(e) {
    console.log(e)
    let applyShop = this.data.applyShop
    let msg = e.currentTarget.dataset.type
    if (msg == 'sex') {
      applyShop[msg] = e.currentTarget.dataset.sex
    } else {
      applyShop[msg] = e.detail.value
    }
    console.log(applyShop)
    this.setData({ applyShop })
    this.setData({ as: false })
  },
  onas() {
    console.log(123)
    wx.createSelectorQuery().select('#as').boundingClientRect(function (rect) {
      console.log(rect)
      // 使页面滚动到底部
      wx.pageScrollTo({
        scrollTop: rect.bottom,
        duration: 300 // 滚动动画时长，单位 ms
      });
    }).exec();
    this.setData({ as: true })
  },
  Readingdetails(e) {
    var _this = this;
    // if(_this.data.zbgoodsType){
    //   return
    // }
    if (_this.data.addresstype == 1) {
      wx.redirectTo({
        url: '/pages/Readingdetails/Readingdetails?step=' + _this.data.step + '&dzy=' + _this.data.dzy + '&status=' + _this.data.status + '&id=' + e.currentTarget.dataset.id + '&ptType=' + _this.data.ptType + '&zbgoodsType=' + _this.data.zbgoodsType,
      })
    } else {
      wx.navigateTo({
        url: '/pages/Readingdetails/Readingdetails?step=' + _this.data.step + '&dzy=' + _this.data.dzy + '&status=' + _this.data.status + '&id=' + e.currentTarget.dataset.id + '&ptType=' + _this.data.ptType + '&zbgoodsType=' + _this.data.zbgoodsType,
      })
    }
    wx.setStorageSync('applyShop', _this.data.applyShop)
    wx.setStorageSync('wait_pay', _this.data.wait_pay)
    wx.setStorageSync('giftId', _this.data.giftId)
    wx.setStorageSync('giftnumber', _this.data.giftnumber)
    wx.setStorageSync('shop_id', _this.data.shop_id)
    wx.setStorageSync('default_lb_num', _this.data.default_lb_num)
    wx.setStorageSync('lb_num_setting', _this.data.lb_num_setting)
    wx.setStorageSync('pay', _this.data.pay)
    wx.setStorageSync('goodsList', _this.data.goodsList)
    wx.setStorageSync('giftInfoList', _this.data.giftInfoList)
  },
  pareventD(e) {

  },
  chooseImage: function () {
    let _this = this
    let imglist = _this.data.imglist
    $api.uploadImagesdt(true).then((res) => {
      let info = res
      info.forEach((item) => {
        imglist.push(item.url)
      })
      _this.setData({ imglist })
      wx.setStorageSync('imglist', imglist)
    })

  },
  FormBind(e) {
    this.setData({ [e.currentTarget.dataset.msg]: e.detail.value })
  },
  onCloseImgs(e) {
    let imglist = this.data.imglist
    imglist.splice(e.currentTarget.dataset.index, 1)
    console.log(imglist)
    this.setData({ imglist })
    wx.setStorageSync('imglist', imglist)
  },
  //返回上一页
  out() {
    wx.navigateBack({
      delta: 1,
    })
  },
})